<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta HTTP-EQUIV="pragma" CONTENT="no-cache">
    <meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
    <meta HTTP-EQUIV="expires" CONTENT="0">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户信息</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/font-awesome.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">
    <link href="css/ui.css" rel="stylesheet">
    <link href="css/layui.css" rel="stylesheet">
    <link href="css/control.css" rel="stylesheet">
    <style>
        #body {
            width: 100%;
            max-height: 100%;
            overflow-y: scroll;
            overflow-x: hidden;
        }

        .articleImg {
            /* width: 100%; */
            /* height: auto !important; */
            max-width: 100px;
        }

        th,
        td {
            text-align: center;
        }
        .textAreaBlock {
            margin-left: 130px;
            min-height: 36px;
        }
        .form_item_align_left {
            text-align: left;
        }
        .from_item_align_center {
            text-align: center;
        }
        .input_own_readonly input {
            background-color: antiquewhite
        }

    </style>
</head>

<body class="gray-bg animated fadeInRight">
    <div id="body">
        <div class="wrapper wrapper-content">
            <div class="row">
                <div class="col-sm-12">
                    <div class="ibox float-e-margins">
                        <div class="ibox-content">

                            <div id="content">

                                <fieldset style="margin-top: 20px">
                                    <legend>用户信息</legend>
                                </fieldset>

                                <div class="layui-form-item form_item_align_left">
                                    <div class="layui-inline input_own_readonly">
                                        <label class="layui-form-label ">登录名</label>
                                        <div class="layui-input-inline">
                                            <input id="userName" readonly="readonly" lay-verify="required|number" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">姓名</label>
                                        <div class="layui-input-inline">
                                            <input id="realName" lay-verify="date" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">手机号</label>
                                        <div class="layui-input-inline">
                                            <input id="mobile" lay-verify="url" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item form_item_align_left">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">邮箱</label>
                                        <div class="layui-input-inline">
                                            <input id="email" lay-verify="required|number" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline input_own_readonly">
                                        <label class="layui-form-label">注册日期</label>
                                        <div class="layui-input-inline">
                                            <input id="createTime" readonly="readonly" lay-verify="date" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline input_own_readonly">
                                        <label class="layui-form-label">最近登录</label>
                                        <div class="layui-input-inline">
                                            <input id="lastLoginTime" readonly="readonly" lay-verify="url" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item form_item_align_left input_own_readonly">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">密码</label>
                                        <div class="layui-input-inline">
                                            <input type="text" readonly="readonly" id="password" placeholder="不可查看，点击重置" lay-verify="required|number" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">app角色</label>
                                        <div class="layui-input-inline">
                                            <input id="appRole" readonly="readonly" id="appRole" lay-verify="required|number" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">pc角色</label>
                                        <div class="layui-input-inline">
                                            <input id="pcRole" readonly="readonly" id="pcRole" lay-verify="required|number" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item form_item_align_left">
                                    <div class="layui-inline layui-form">
                                        <label class="layui-form-label">状态</label>
                                        <div class="layui-input-inline ">
                                            <select id="accountStatus">
                                                <option value="0" >正常</option>
                                                <option value="1" >禁用</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="from_item_align_center">
                                <button class="btn btn-info layui-btn-normal uptAccount" style="margin-left: 20px">确&nbsp;&nbsp;&nbsp;&nbsp;定</button>
                                <button class="btn btn-warning layui-btn-warm cancle" style="margin-left: 30px">取&nbsp;&nbsp;&nbsp;&nbsp;消</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 全局js -->
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/work/common.js"></script>
    <!--<script src="js/plugins/laydate/laydate.js"></script>-->
    <script src="js/plugins/layer/layer.min.js"></script>
    <script src="js/plugins/layer/layer.js"></script>
    <script src="js/layui.js"></script>
    <!-- 自定义js -->
    <script src="js/content.js"></script>
    <script>

        layui.use(['form'], function(){});
        var userId = getStorage("userId");
        $(document).ready(function () {
            initUserDetail();

            // 修改信息
            $('.uptAccount').click(function () {
                updateAccountInfo();
            });
            // 取消操作
            $('.cancle').click(function () {
                window.location.href = "usermanage.html";
            });

            // 重置密码
            $("#password").click(function () {
                layer.open({
                    type: 2,
                    title: '重置密码',
                    maxmin: true,
                    shadeClose: false, //点击遮罩关闭层
                    closeBtn: 1,
                    maxmin: false,
                    area: ['500px', '300px'],
                    content: 'passwordRest.html'
                });
            });
        });


        function initUserDetail() {
            ajax({
                url: "userm/getAccountDetail",
                type: "GET",
                dataType: 'jsonp',
                jsonp: "callback",
                async: true,
                data: {userId:userId},
                timeout: 8000,
                error: function (xhr, type) {
                    layer.msg("服务器异常，请稍后重试！", {time:2000})
                },
                successx: function (data) {
                    if (data.success == true) {
                        setUserInfo(data.data);
                    } else {
                        layer.msg(data.message,{time:1000})
                    }
                }
            });
        }

        // 初始化信息展示
        function setUserInfo(data) {
            $("#userName").val(data.userName);
            $("#realName").val(data.realName);
            $("#mobile").val(data.mobile);
            $("#email").val(data.email);
            $("#createTime").val(timeStamp2String(data.createTime, "ymdhms"));
            $("#lastLoginTime").val(timeStamp2String(data.lastLoginTime, "ymdhms"));
            $("#appRole").val(data.appRoleName);
            $("#pcRole").val(data.pcRoleName);
            $("#accountStatus").val(data.accountStatus);
            layui.form.render('select'); //刷新select选择框渲染

            // $(".accountStatus").find('option[value='+data.accountStatus+']').attr("selected",true);
        }


        function updateAccountInfo() {

            var realName = $("#realName").val();
            var mobile = $("#mobile").val();
            var email = $("#email").val();
            var status = $("#accountStatus").val();

            ajax({
                url: "userm/updateAccountInfo",
                type: "POST",
                contentType: "application/json;charset=UTF-8",
                dataType: "json",
                xhrFields: {
                    withCredentials: true
                },
                crossDomain: true,
                data: JSON.stringify({
                    userId:userId,
                    realName:realName,
                    mobile:mobile,
                    email:email,
                    accountStatus:status
                }),
                error: function (xhr, type) {
                    layer.msg("服务器异常，请稍后重试！", {time:2000})
                },
                successx: function (data) {
                    console.log(data);
                    if (data.success == true) {
                        window.location.href = "usermanage.html";
                    } else {
                        layer.msg(data.message,{time:1000})
                    }
                }
            });
        }
    </script>
</body>

</html>